home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mgr / sparcmgr / src.zoo / src / write_ok.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-17  |  2.0 KB  |  76 lines

  1. /*                        Copyright (c) 1987 Bellcore
  2.  *                            All Rights Reserved
  3.  *       Permission is granted to copy or use this program, EXCEPT that it
  4.  *       may not be sold for profit, the copyright notice must be reproduced
  5.  *       on copies, and credit should be given to Bellcore where it is due.
  6.  *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7.  */
  8. /*    $Header: write_ok.c,v 1.1 89/03/17 08:21:26 sau Exp $
  9.     $Source: /m1/mgr.new/src/RCS/write_ok.c,v $
  10. */
  11. static char    RCSid_[] = "$Source: /m1/mgr.new/src/RCS/write_ok.c,v $$Revision: 1.1 $";
  12.  
  13. /* check to make sure it is ok to read/write a file */
  14.  
  15. #include <sys/types.h>
  16. #include <sys/stat.h>
  17. #include <sys/file.h>
  18.  
  19. #include "defines.h"
  20. #define Type(file)        (stat(file,&buff) ? 0 : buff.st_mode&S_IFMT)
  21.  
  22. /* ok for user to write this file */
  23. int
  24. write_ok(name)
  25. register char *name;        /* path name of file */
  26.    {
  27.    struct stat buff;
  28.    char dir[MAX_PATH];
  29.    char *strcpy(), *rindex();
  30.    char *ptr;
  31.    int result;
  32.  
  33.    if (access(name,F_OK)==0) {
  34.       result = (Type(name)==S_IFREG && access(name,W_OK)==0);
  35.       }
  36.    else if (ptr=rindex(strcpy(dir,name),'/')) {
  37.       *ptr = '\0';
  38.       result = (access(dir,W_OK)==0 && Type(dir) == S_IFDIR);
  39.       }
  40.    else {
  41.       result = (access(".",W_OK)==0);
  42.       }
  43.    return(result);
  44.    }
  45.  
  46. /* see if ok to read a file */
  47.  
  48. int
  49. read_ok(name)
  50. register char *name;        /* path name of file */
  51.    {
  52.    struct stat buff;
  53.    extern char *icon_dir;
  54.    char *rindex();
  55.  
  56.    if (access(name,R_OK)==0) {
  57.       return(1);
  58.       }
  59.    if (strncmp(name,icon_dir,strlen(icon_dir)) == 0 &&
  60.             rindex(name,'.')==(char *) 0 && stat(name,buff)==0)
  61.       return(buff.st_mode == S_IFREG);
  62.    }
  63.  
  64. /* make sure tty mode is ok for message passing */
  65.  
  66. int
  67. mode_ok(name,mask)
  68. char *name;        /* file to check mode for */
  69. int mask;        /* these bits must be turned off */
  70.    {
  71.    struct stat buff;
  72.    if (stat(name,&buff) < 0)
  73.       return(0);
  74.    return((buff.st_mode&mask) == 0);
  75.    }
  76.